import TextWidget from './text-widget.js'
import {WIDGET_TYPE} from './widget-const.js';

const _template = Object.freeze({
    content: "人的智慧掌握着三把钥匙，一把开启数字，一把开启字母，一把开启音符。知识、思想、幻想就在其中。",
    author: "雨果",
});

export default class TODOWidget extends TextWidget {
    constructor(sectionData, dispatcher) {
        super(sectionData, dispatcher);
        try {
            this._data = JSON.stringify(this._sectionData.content ?? _template, null, 4);
        } catch (e) {
            this._data = JSON.stringify(_template, null, 4);
            console.error(e);
        }
    }
    get sectionData() {
        this._sectionData.type = WIDGET_TYPE.QUOTE;
        this._sectionData.content = JSON.parse(this._data);
        return this._sectionData;
    }
    get language() {return 'json';}
    get textareaText() {return this._data;}
    set textareaText(value) {this._data = value;}
    Init() {
        super.Init();
        this._viewContainerElem.classList.add("scroll", "scroll-horizontal");
        this._editContainerElem.setAttribute('data-language', 'todo');
        return this;
    }
    _UpdateView() {
        try {
            const _data = JSON.parse(this._data);
            let _HTMLText = `<figure>
  <blockquote class="blockquote">
    <p>${_data.content}
  <figcaption class="blockquote-footer">
    ${_data.author}
  </figcaption>
  </blockquote>
</figure>`;
            this._viewContainerElem.innerHTML = _HTMLText;
        } catch (e) {
            this._viewContainerElem.innerText = e.message;
            console.log(e.stack);
        }
    }
};

